Object.defineProperty(exports, "__esModule", {
    value: !0
});

var t = {
    version: 20180830,
    jsonHost: "https://router.polyv.net/proxy/",
    currentTime: 0,
    state: "end",
    apiState: "end",
    wholeTime: 0,
    time: 0,
    detailTime: 0,
    stateEverLive: !1,
    streamName: "",
    timeStamp: 0,
    uid: "",
    cid: "",
    pid: "",
    apiUrl: "",
    stateMode: 0,
    param1: "",
    param2: "",
    param3: "",
    param4: "",
    param5: "webapp",
    renderTimeout: null,
    getVersion: function() {
        return this.version;
    },
    getVideo: function(t) {
        this.options = t;
        var a = this, e = {};
        if ("" == t.uid || "" == t.vid) return e = {
            code: 0,
            error: "lack of uid/vid"
        }, void this.showError(e);
        a.videoContext = t.videoContext, a.uid = t.uid, a.cid = t.vid, a.pid = "" == a.pid ? a.getPlayId() : a.pid, 
        t.params && (t.params.param1 && (a.param1 = t.params.param1), t.params.param2 && (a.param2 = t.params.param2), 
        t.params.param3 && (a.param3 = t.params.param3), t.params.param4 && (a.param4 = t.params.param4), 
        t.params.param5 && (a.param5 = t.params.param5)), wx.request({
            url: "https://player.polyv.net/service/v1/channel_" + a.uid + "_" + a.cid + ".json?ran=" + Math.floor(9999999 * Math.random()),
            method: "GET",
            success: function(t) {
                e.title = t.data.name, e.src = t.data.m3u8Url, e.poster = a.proxyUrl(t.data.coverImage), 
                e.waitImage = a.proxyUrl(t.data.waitImage), e.logoImage = a.proxyUrl(t.data.logoImage), 
                e.logoHref = a.proxyUrl(t.data.logoHref), e.logoOpacity = t.data.logoOpacity, e.logoPosition = t.data.logoPosition, 
                "Y" == t.data.isOnlyAudio && (src.indexOf("?") > -1 ? e.src = e.src + "&only-audio=1" : e.src = e.src + "?only-audio=1"), 
                e.flvSrc = t.data.url + t.data.stream + ".flv", "Y" == t.data.isNgbEnabled ? e.flvSrc = t.data.ngbUrl + t.data.stream + ".flv" : "Y" == t.data.isUrlProtected && (e.flvSrc = t.data.bakUrl + t.data.stream + ".flv"), 
                "Y" == t.data.isUrlProtected && (e.flvSrc = e.flvSrc + "?wsSecret=" + t.data.streamSign + "&wsTime=" + t.data.currentTimeSecs), 
                a.options.success && a.options.success(e), a.streamName = t.data.stream, a.apiUrl = "https://api.polyv.net/live/live_status/query?stream=" + a.streamName, 
                a.render(), a.countInterval && clearInterval(a.countInterval), a.countInterval = setInterval(function() {
                    a.countWholeTime();
                }, 1e3);
            },
            fail: function(t) {
                e = {
                    code: 1,
                    error: "load json fail"
                }, showError(e);
            }
        });
    },
    getNewVideo: function(t) {
        this.getChannel().then(function(a) {
            "function" == typeof t && t(a);
        });
    },
    getChannel: function() {
        var t = this;
        return new Promise(function(a, e) {
            wx.request({
                url: "https://player.polyv.net/service/v1/channel_" + t.uid + "_" + t.cid + ".json?ran=" + Math.floor(9999999 * Math.random()),
                method: "GET",
                success: function(e) {
                    var r = {};
                    r.title = e.data.name, r.src = e.data.m3u8Url, r.poster = t.proxyUrl(e.data.coverImage), 
                    r.waitImage = t.proxyUrl(e.data.waitImage), r.logoImage = t.proxyUrl(e.data.logoImage), 
                    r.logoHref = t.proxyUrl(e.data.logoHref), r.logoOpacity = e.data.logoOpacity, r.logoPosition = e.data.logoPosition, 
                    "Y" === e.data.isOnlyAudio && (src.indexOf("?") > -1 ? r.src = r.src + "&only-audio=1" : r.src = r.src + "?only-audio=1"), 
                    r.flvSrc = e.data.url + e.data.stream + ".flv", "Y" == e.data.isNgbEnabled ? r.flvSrc = e.data.ngbUrl + e.data.stream + ".flv" : "Y" == e.data.isUrlProtected && (r.flvSrc = e.data.bakUrl + e.data.stream + ".flv"), 
                    "Y" == e.data.isUrlProtected && (r.flvSrc = r.flvSrc + "?wsSecret=" + e.data.streamSign + "&wsTime=" + e.data.currentTimeSecs), 
                    a(r);
                }
            });
        });
    },
    timeUpdate: function(t) {
        t && t.detail && t.detail.currentTime && (this.detailTime = t.detail.currentTime);
    },
    play: function() {},
    pause: function() {},
    ended: function() {},
    render: function() {
        var t = this;
        "end" == t.state && t.stateEverLive, this.renderTimeout = setTimeout(function() {
            t.render();
        }, 5e3);
    },
    countWholeTime: function() {
        var t = this, a = new Date().getTime();
        t.updateState(), a - t.timeStamp > 6e3 && (t.timeStamp = a, t.updateApiState(), 
        t.sendState()), "live" == t.apiState && t.wholeTime++, "live" == t.state && t.time++;
    },
    updateState: function() {
        this.currentTime == this.detailTime ? this.state = "end" : (this.stateMode = 1, 
        this.stateEverLive = !0, this.state = "live", this.currentTime = this.detailTime);
    },
    updateApiState: function() {
        var t = this;
        "" != t.streamName && wx.request({
            url: t.apiUrl,
            dataType: "jsonp",
            success: function(a) {
                var e = !1;
                -1 === t.apiState.indexOf("live") && a.data.indexOf("live") > -1 && (e = !0), e && t.options.onStartLive && t.options.onStartLive(), 
                t.apiState = a.data.indexOf("live") > -1 ? "live" : "end", t.options.onApiStatus && t.options.onApiStatus(t.apiState);
            }
        });
    },
    sendState: function() {
        var t = this, e = 0;
        if ((e = 0 == t.stateMode ? t.wholeTime : t.time) > 0 && ("live" === t.state || "live" === t.apiState)) {
            var r = new Date().getTime(), i = "rtas.net" + t.pid + t.cid + "0" + e, o = a(i) + "", n = {
                pid: t.pid,
                uid: t.uid,
                cid: t.cid,
                pd: e,
                sd: e,
                sign: o,
                flow: 0,
                ts: r,
                param1: t.param1,
                param2: t.param2,
                param3: t.param3,
                param4: t.param4,
                param5: t.param5
            };
            wx.request({
                url: "https://rtas.videocc.net/v1/view",
                data: n
            });
        }
    },
    getPlayId: function() {
        return new Date().getTime() + "" + "X" + (parseInt(1e6 * Math.random() + 1e6) + "");
    },
    proxyUrl: function(t) {
        return "" == (t = t.replace(/.*?:\/\//g, "")) ? t : "https://router.polyv.net/proxy/" + t;
    },
    showError: function(t) {
        this.options.error && this.options.error(t);
    },
    destroy: function() {
        this.countInterval && clearInterval(this.countInterval), this.renderTimeout && clearTimeout(this.renderTimeout);
    }
}, a = function(t) {
    function a(t, a) {
        return t << a | t >>> 32 - a;
    }
    function e(t, a) {
        var e, r, i, o, n;
        return i = 2147483648 & t, o = 2147483648 & a, n = (1073741823 & t) + (1073741823 & a), 
        (e = 1073741824 & t) & (r = 1073741824 & a) ? 2147483648 ^ n ^ i ^ o : e | r ? 1073741824 & n ? 3221225472 ^ n ^ i ^ o : 1073741824 ^ n ^ i ^ o : n ^ i ^ o;
    }
    function r(t, r, i, o, n, s, d) {
        return t = e(t, e(e(function(t, a, e) {
            return t & a | ~t & e;
        }(r, i, o), n), d)), e(a(t, s), r);
    }
    function i(t, r, i, o, n, s, d) {
        return t = e(t, e(e(function(t, a, e) {
            return t & e | a & ~e;
        }(r, i, o), n), d)), e(a(t, s), r);
    }
    function o(t, r, i, o, n, s, d) {
        return t = e(t, e(e(function(t, a, e) {
            return t ^ a ^ e;
        }(r, i, o), n), d)), e(a(t, s), r);
    }
    function n(t, r, i, o, n, s, d) {
        return t = e(t, e(e(function(t, a, e) {
            return a ^ (t | ~e);
        }(r, i, o), n), d)), e(a(t, s), r);
    }
    function s(t) {
        var a, e = "", r = "";
        for (a = 0; a <= 3; a++) e += (r = "0" + (t >>> 8 * a & 255).toString(16)).substr(r.length - 2, 2);
        return e;
    }
    var d, l, u, c, p, m, f, v, h, g = Array();
    for (g = function(t) {
        for (var a, e = t.length, r = e + 8, i = 16 * ((r - r % 64) / 64 + 1), o = Array(i - 1), n = 0, s = 0; s < e; ) n = s % 4 * 8, 
        o[a = (s - s % 4) / 4] = o[a] | t.charCodeAt(s) << n, s++;
        return n = s % 4 * 8, o[a = (s - s % 4) / 4] = o[a] | 128 << n, o[i - 2] = e << 3, 
        o[i - 1] = e >>> 29, o;
    }(t = function(t) {
        t = t.replace(/\r\n/g, "\n");
        for (var a = "", e = 0; e < t.length; e++) {
            var r = t.charCodeAt(e);
            r < 128 ? a += String.fromCharCode(r) : r > 127 && r < 2048 ? (a += String.fromCharCode(r >> 6 | 192), 
            a += String.fromCharCode(63 & r | 128)) : (a += String.fromCharCode(r >> 12 | 224), 
            a += String.fromCharCode(r >> 6 & 63 | 128), a += String.fromCharCode(63 & r | 128));
        }
        return a;
    }(t)), m = 1732584193, f = 4023233417, v = 2562383102, h = 271733878, d = 0; d < g.length; d += 16) l = m, 
    u = f, c = v, p = h, m = r(m, f, v, h, g[d + 0], 7, 3614090360), h = r(h, m, f, v, g[d + 1], 12, 3905402710), 
    v = r(v, h, m, f, g[d + 2], 17, 606105819), f = r(f, v, h, m, g[d + 3], 22, 3250441966), 
    m = r(m, f, v, h, g[d + 4], 7, 4118548399), h = r(h, m, f, v, g[d + 5], 12, 1200080426), 
    v = r(v, h, m, f, g[d + 6], 17, 2821735955), f = r(f, v, h, m, g[d + 7], 22, 4249261313), 
    m = r(m, f, v, h, g[d + 8], 7, 1770035416), h = r(h, m, f, v, g[d + 9], 12, 2336552879), 
    v = r(v, h, m, f, g[d + 10], 17, 4294925233), f = r(f, v, h, m, g[d + 11], 22, 2304563134), 
    m = r(m, f, v, h, g[d + 12], 7, 1804603682), h = r(h, m, f, v, g[d + 13], 12, 4254626195), 
    v = r(v, h, m, f, g[d + 14], 17, 2792965006), m = i(m, f = r(f, v, h, m, g[d + 15], 22, 1236535329), v, h, g[d + 1], 5, 4129170786), 
    h = i(h, m, f, v, g[d + 6], 9, 3225465664), v = i(v, h, m, f, g[d + 11], 14, 643717713), 
    f = i(f, v, h, m, g[d + 0], 20, 3921069994), m = i(m, f, v, h, g[d + 5], 5, 3593408605), 
    h = i(h, m, f, v, g[d + 10], 9, 38016083), v = i(v, h, m, f, g[d + 15], 14, 3634488961), 
    f = i(f, v, h, m, g[d + 4], 20, 3889429448), m = i(m, f, v, h, g[d + 9], 5, 568446438), 
    h = i(h, m, f, v, g[d + 14], 9, 3275163606), v = i(v, h, m, f, g[d + 3], 14, 4107603335), 
    f = i(f, v, h, m, g[d + 8], 20, 1163531501), m = i(m, f, v, h, g[d + 13], 5, 2850285829), 
    h = i(h, m, f, v, g[d + 2], 9, 4243563512), v = i(v, h, m, f, g[d + 7], 14, 1735328473), 
    m = o(m, f = i(f, v, h, m, g[d + 12], 20, 2368359562), v, h, g[d + 5], 4, 4294588738), 
    h = o(h, m, f, v, g[d + 8], 11, 2272392833), v = o(v, h, m, f, g[d + 11], 16, 1839030562), 
    f = o(f, v, h, m, g[d + 14], 23, 4259657740), m = o(m, f, v, h, g[d + 1], 4, 2763975236), 
    h = o(h, m, f, v, g[d + 4], 11, 1272893353), v = o(v, h, m, f, g[d + 7], 16, 4139469664), 
    f = o(f, v, h, m, g[d + 10], 23, 3200236656), m = o(m, f, v, h, g[d + 13], 4, 681279174), 
    h = o(h, m, f, v, g[d + 0], 11, 3936430074), v = o(v, h, m, f, g[d + 3], 16, 3572445317), 
    f = o(f, v, h, m, g[d + 6], 23, 76029189), m = o(m, f, v, h, g[d + 9], 4, 3654602809), 
    h = o(h, m, f, v, g[d + 12], 11, 3873151461), v = o(v, h, m, f, g[d + 15], 16, 530742520), 
    m = n(m, f = o(f, v, h, m, g[d + 2], 23, 3299628645), v, h, g[d + 0], 6, 4096336452), 
    h = n(h, m, f, v, g[d + 7], 10, 1126891415), v = n(v, h, m, f, g[d + 14], 15, 2878612391), 
    f = n(f, v, h, m, g[d + 5], 21, 4237533241), m = n(m, f, v, h, g[d + 12], 6, 1700485571), 
    h = n(h, m, f, v, g[d + 3], 10, 2399980690), v = n(v, h, m, f, g[d + 10], 15, 4293915773), 
    f = n(f, v, h, m, g[d + 1], 21, 2240044497), m = n(m, f, v, h, g[d + 8], 6, 1873313359), 
    h = n(h, m, f, v, g[d + 15], 10, 4264355552), v = n(v, h, m, f, g[d + 6], 15, 2734768916), 
    f = n(f, v, h, m, g[d + 13], 21, 1309151649), m = n(m, f, v, h, g[d + 4], 6, 4149444226), 
    h = n(h, m, f, v, g[d + 11], 10, 3174756917), v = n(v, h, m, f, g[d + 2], 15, 718787259), 
    f = n(f, v, h, m, g[d + 9], 21, 3951481745), m = e(m, l), f = e(f, u), v = e(v, c), 
    h = e(h, p);
    return (s(m) + s(f) + s(v) + s(h)).toLowerCase();
};

exports.default = t;